﻿using System.Collections.ObjectModel;
using Ninject.Core.Parameters;
using TestBat.IModels.Domain;
using TestBat.IModels.Models;
using TestBat.IViewModels.Base;
using TestBat.IViewModels.Workspaces.Trainees;
using TestBat.ServiceLocator;

namespace TestBat.ViewModels.Workspaces.Trainees
{
    public class TraineeListViewModel : ListViewModel<ITraineeViewModel, ObservableCollection<ITraineeViewModel>>, ITraineeListViewModel
    {
        public TraineeListViewModel(ITraineeModel traineeModel, ITraineeGroupModel traineeGroupModel)
            : base(true)
        {
            this.traineeModel = traineeModel;
            this.traineeGroupModel = traineeGroupModel;
        }

        protected override ObservableCollection<ITraineeViewModel> _RecreateItems()
        {
            ObservableCollection<ITraineeViewModel> list = new ObservableCollection<ITraineeViewModel>();
            foreach (ITrainee t in traineeModel.GetAll())
            {
                var traineeViewModel = DefaultServiceLocator.Get<ITraineeViewModel>(With.Parameters.ConstructorArgument("trainee", t)); // TODO: use factory
                list.Add(traineeViewModel);
            }

            return list;
        }

        //[CheckUnsavedChanges]
        //protected override void ChangeSelected(ITraineeViewModel from, ITraineeViewModel to)
        //{
        //    base.ChangeSelected(from, to);
        //}

        private readonly ITraineeGroupModel traineeGroupModel;
        private readonly ITraineeModel traineeModel;
    }
}
